#!/usr/bin/python
#
# Copyright (C) 2008 rambla.be
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

""" Contains the objects required for RATS format resource access. """

try:
  from xml.etree import cElementTree as ElementTree
except ImportError:
  try:
    import cElementTree as ElementTree
  except ImportError:
    from elementtree import ElementTree

import atom
import rawsc
from rawsc import RAWS_NAMESPACE
from rawsc.rats import *

class FormatParams(rawsc.RawsParams):
    """ Handler for the <raws:params> element (= sub-element of atom:content). """
    _children = {}
    _children['{%s}id' % rawsc.RAWS_NAMESPACE] = ('id', Id)
    _children['{%s}name' % RAWS_NAMESPACE] = ('name', Name)
    _children['{%s}description' % RAWS_NAMESPACE] = ('description', Description)
    _children['{%s}category' % rawsc.RAWS_NAMESPACE] = ('category', Category)
    _children['{%s}container' % RAWS_NAMESPACE] = ('container', Container)
    _children['{%s}video_codec' % RAWS_NAMESPACE] = ('video_codec', VideoCodec)
    _children['{%s}video_bitrate' % RAWS_NAMESPACE] = ('video_bitrate', VideoBitrate)
    _children['{%s}video_fps' % RAWS_NAMESPACE] = ('video_fps', VideoFps)
    _children['{%s}video_width' % RAWS_NAMESPACE] = ('video_width', VideoWidth)
    _children['{%s}video_height' % RAWS_NAMESPACE] = ('video_height', VideoHeight)
    _children['{%s}video_aspect_ratio' % RAWS_NAMESPACE] = ('video_aspect_ratio', VideoAspectRatio)
    _children['{%s}video_deinterlace' % RAWS_NAMESPACE] = ('video_deinterlace', VideoDeinterlace)
    _children['{%s}video_cq' % RAWS_NAMESPACE] = ('video_cq', VideoCq)
    _children['{%s}video_passes' % RAWS_NAMESPACE] = ('video_passes', VideoPasses)
    _children['{%s}video_crop_top' % RAWS_NAMESPACE] = ('video_crop_top', VideoCropTop)
    _children['{%s}video_crop_bottom' % RAWS_NAMESPACE] = ('video_crop_bottom', VideoCropBottom)
    _children['{%s}video_crop_right' % RAWS_NAMESPACE] = ('video_crop_right', VideoCropRight)
    _children['{%s}video_crop_left' % RAWS_NAMESPACE] = ('video_crop_left', VideoCropLeft)
    _children['{%s}audio_channel' % RAWS_NAMESPACE] = ('audio_channel', AudioChannel)
    _children['{%s}audio_codec' % RAWS_NAMESPACE] = ('audio_codec', AudioCodec)
    _children['{%s}audio_bitrate' % RAWS_NAMESPACE] = ('audio_bitrate', AudioBitrate)
    _children['{%s}audio_sample_rate' % RAWS_NAMESPACE] = ('audio_sample_rate', AudioSampleRate)
    _children['{%s}audio_passes' % RAWS_NAMESPACE] = ('audio_passes', AudioPasses)
    _children['{%s}audio_track_mapping' % RAWS_NAMESPACE] = ('audio_track_mapping', AudioTrackMapping)
    _children['{%s}hinting' % RAWS_NAMESPACE] = ('hinting', Hinting)
    _children['{%s}input' % RAWS_NAMESPACE] = ('input', Input)
    _children['{%s}output' % RAWS_NAMESPACE] = ('output', Output)
    _children['{%s}overlay' % RAWS_NAMESPACE] = ('overlay', Overlay)

    def __init__(self, id=None, name=None, description=None, category=None, container=None, 
                 video_codec=None, video_bitrate=None, video_fps=None, video_width = None, video_height = None, video_aspect_ratio = None, 
                 video_deinterlace = None, video_cq = None, video_passes=None, 
                 video_crop_top=None, video_crop_bottom=None, video_crop_right = None, video_crop_left = None,
                 audio_channel=None, audio_codec=None, audio_bitrate=None, audio_sample_rate = None, audio_passes = None, audio_track_mapping = None,
                 hinting=None, input=None, output=None, overlay = None):
        rawsc.RawsParams.__init__(self, extension_elements=None, extension_attributes=None)
        self.id = Id(text = id)
        self.name = Name(text = name)
        self.description = Description(text = description)
        self.category = Category(text = category)
        self.container = Container(text = container)
        self.video_codec = VideoCodec(text = video_codec)
        self.video_bitrate = VideoBitrate(text = video_bitrate)
        self.video_fps = VideoFps(text = video_fps)
        self.video_width = VideoWidth(text = video_width)
        self.video_height = VideoHeight(text = video_height)
        self.video_aspect_ratio = VideoAspectRatio(text = video_aspect_ratio)
        self.video_deinterlace = VideoDeinterlace(text = video_deinterlace)
        self.video_cq = VideoCq(text = video_cq)
        self.video_passes = VideoPasses(text = video_passes)
        self.video_crop_top = VideoCropTop(text = video_crop_top)
        self.video_crop_bottom = VideoCropBottom(text = video_crop_bottom)
        self.video_crop_right = VideoCropRight(text = video_crop_right)
        self.video_crop_left = VideoCropLeft(text = video_crop_left)
        self.audio_channel = AudioChannel(text = audio_channel)
        self.audio_codec = AudioCodec(text = audio_codec)
        self.audio_bitrate = AudioBitrate(text = audio_bitrate)
        self.audio_sample_rate = AudioSampleRate(text = audio_sample_rate)
        self.audio_passes = AudioPasses(text = audio_passes)
        self.audio_track_mapping = AudioTrackMapping(text = audio_track_mapping)
        self.hinting = Hinting(text = hinting)
        self.input = Input(text = input)
        self.output = Output(text = output)
        self.overlay = Overlay(text = overlay)

def FormatParamsFromString(xml_string):
    return atom.CreateClassFromXMLString(FormatParams, xml_string)   


class FormatContent(rawsc.RawsContent):
    """ Handler for the atom:content element, in a RAWS context. """
    _children = atom.AtomBase._children.copy()
    _children['{%s}params' % (RAWS_NAMESPACE)] = ('params', FormatParams)
    
    params = None
    
    def __init__(self, params=None):
        rawsc.RawsContent.__init__(self, extension_elements=None, extension_attributes=None)
        self.params = FormatParams()
        if params:
            self.params = params
    
def FormatContentFromString(xml_string):
    return atom.CreateClassFromXMLString(FormatContent, xml_string)   
    

class FormatEntry(rawsc.RawsEntry):
    """ Handler for an entry that is returned by the RATS format resource."""
    _children = rawsc.RawsEntry._children.copy()
    _children['{%s}content' % atom.ATOM_NAMESPACE] = ('content', FormatContent)

    def __init__(self, author=None, category=None, atom_id=None, link=None, published=None, title=None, updated=None, content = None, extension_elements=None, extension_attributes=None):
        rawsc.RawsEntry.__init__(self, author=author, category=category, atom_id=atom_id, link=link, published=published, title=title, updated=updated,
                                extension_elements=extension_elements, extension_attributes=extension_attributes)
        self.content = FormatContent()
        if content:
            self.content = content

def FormatEntryFromString(xml_string):
    return atom.CreateClassFromXMLString(FormatEntry, xml_string)
    

class FormatFeed(rawsc.RawsFeed, rawsc.LinkFinder):
    """ Handler for a feed that is returned by the RATS format resource."""
    _children = rawsc.RawsFeed._children.copy()
    _children['{%s}entry' % atom.ATOM_NAMESPACE] = ('entry', [FormatEntry])

def FormatFeedFromString(xml_string):
  return atom.CreateClassFromXMLString(FormatFeed, xml_string)

